package com.tuanzi.loan.business.repository.family.impl;

import com.tuanzi.loan.business.repository.family.custom.LoanLargeOuterTemplateRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.family.LoanLargeOuterTempLateListRequest;
import com.tuanzi.loan.vo.response.family.LoanLargeOuterTempLateListResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;

import static com.tuanzi.loan.generated.jooq.loan.Tables.LOAN_LARGE_OUTER_TEMPLATE;

/**
 * User: liangZongXi
 * Create time: 14:24 2019/6/4
 * Description:
 */
@Repository
public class LoanLargeOuterTemplateRepositoryImpl  extends JOOQBaseRepository implements LoanLargeOuterTemplateRepositoryCustom {
    @Override
    public Page<LoanLargeOuterTempLateListResponse> list(LoanLargeOuterTempLateListRequest searchRequest, Pageable pageable) {
        fields(LOAN_LARGE_OUTER_TEMPLATE.ID, LOAN_LARGE_OUTER_TEMPLATE.TEMPLATE_ID, LOAN_LARGE_OUTER_TEMPLATE.TEMPLATE_NAME,
                LOAN_LARGE_OUTER_TEMPLATE.CREATOR, LOAN_LARGE_OUTER_TEMPLATE.CREATE_TIME,
                LOAN_LARGE_OUTER_TEMPLATE.UPDATOR, LOAN_LARGE_OUTER_TEMPLATE.UPDATE_TIME);

        eq(LOAN_LARGE_OUTER_TEMPLATE.TEMPLATE_ID, searchRequest.getTemplateId());
        contains(LOAN_LARGE_OUTER_TEMPLATE.TEMPLATE_NAME, searchRequest.getTemplateName());
        orderBy(LOAN_LARGE_OUTER_TEMPLATE.CREATE_TIME, Sort.Direction.DESC);

        return search(pageable, record -> {
            LoanLargeOuterTempLateListResponse response = new LoanLargeOuterTempLateListResponse();
            response.setId(record.get(LOAN_LARGE_OUTER_TEMPLATE.ID));
            response.setTemplateId(record.get(LOAN_LARGE_OUTER_TEMPLATE.TEMPLATE_ID));
            response.setTemplateName(record.get(LOAN_LARGE_OUTER_TEMPLATE.TEMPLATE_NAME));
            response.setCreator(record.get(LOAN_LARGE_OUTER_TEMPLATE.CREATOR));
            response.setCreateTime(record.get(LOAN_LARGE_OUTER_TEMPLATE.CREATE_TIME));
            response.setUpdator(record.get(LOAN_LARGE_OUTER_TEMPLATE.UPDATOR));
            response.setUpdateTime(record.get(LOAN_LARGE_OUTER_TEMPLATE.UPDATE_TIME));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_LARGE_OUTER_TEMPLATE;
    }
}
